﻿using System.Collections.Generic;
using Moq;
using YoProgramo.Domain.Core.Entities;
using YoProgramo.Infrastructure.Data.Repositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using YoProgramo.Domain.Core.Interfaces;

namespace YoProgramo.Infrastructure.Data.Test
{
    
    
    /// <summary>
    ///This is a test class for TagRepositoryFact and is intended
    ///to contain all TagRepositoryFact Unit Tests
    ///</summary>
    [TestClass()]
    public class TagRepositoryFact {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetById
        ///</summary>
        [TestMethod()]
        public void GetByIdFact() {
            var dao = new Mock<IDao<Tag, ITag, long>>();

            var FakeTag = new Tag();
            FakeTag.Id = 1;
            FakeTag.Name = "Internet";

            dao.Setup(w => w.GetById(1)).Returns(FakeTag);

            TagRepository target = new TagRepository(dao.Object); // TODO: Initialize to an appropriate value

            Assert.IsNotNull(target.Get(1));
            Assert.AreEqual(target.Get(1).Name, "Internet");
            Assert.IsNull(target.Get(2));
        }


        /// <summary>
        ///A test for FindByName
        ///</summary>
        [TestMethod()]
        public void FindByNameFact() {
            var dao = new Mock<IDao<Tag, ITag, long>>();

            dao.Setup(w => w.GetAll()).Returns(GetFakeTagsList());

            TagRepository target = new TagRepository(dao.Object); // TODO: Initialize to an appropriate value

            Assert.IsNotNull(target.Get(1));
            Assert.IsNull(target.FindByName("po"));
        }


        /// <summary>
        ///A test for GetAll
        ///</summary>
        [TestMethod()]
        public void GetAllFact() {
            var dao = new Mock<IDao<Tag, ITag, long>>();

            dao.Setup(w => w.GetAll()).Returns(GetFakeTagsList());

            TagRepository target = new TagRepository(dao.Object); // TODO: Initialize to an appropriate value

            Assert.IsNotNull(target.GetAll());
            Assert.AreEqual(target.GetAll().Count, 3);
        }


        public IList<ITag> GetFakeTagsList()
        {
            IList<ITag> taglist = new List<ITag>();
            ITag tag = new Tag();
            tag.Name = "C";
            taglist.Add(tag);

            tag = new Tag();
            tag.Name = "D";
            taglist.Add(tag);

            tag = new Tag();
            tag.Name = "Internet";
            taglist.Add(tag);
            return taglist;
        }

    }
}
